// test for GraphList

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
 
using namespace std;
 
// 边
struct Edge{
	int vName;
	struct Edge* next;
};
 
// 顶点(链表头)
struct Vertex{
	int vName;
	struct Edge* next;
};
 
// 有向图
class GraphList
{
public:
	~GraphList();
 
	void createGraph();
	void printGraph();
 
private:
	// 1. 输入定点数
	void inputVertexCount(int m_vcount);
	// 2. 生成定点数组
	void makeVertexArray();
	// 3. 输入边数
	void inputEdgeCount(int m_ecount);
	// 4. 输入边的起始点
	void inputEdgeInfo();
	// 5. 添加边节点至对应的链表中
	void addEdgeToList(int vFrom, int vTo);
private:
	int m_vCount;
	int m_eCount;
	Vertex* m_vVertex;
};
 
GraphList::~GraphList(){
	for (int i = 0; i < m_vCount; ++i){
		Edge* tmp = m_vVertex[i].next;
		Edge* edge = NULL;
		while(tmp){
			edge = tmp;
			tmp = tmp->next;
			delete edge;
			edge = NULL;
		}
	}
	delete[] m_vVertex;
}
 
void GraphList::inputVertexCount(int m_vcount)
{

	m_vCount=m_vcount;
}
 
void GraphList::makeVertexArray()
{
	m_vVertex = new Vertex[m_vCount];
	// 初始化
	for (int i = 0; i < m_vCount; ++i){
		m_vVertex[i].vName = i;
		m_vVertex[i].next = NULL;
	}
}
 
void GraphList::inputEdgeCount(int m_ecount)
{
	m_eCount=m_ecount;
}
 
void GraphList::inputEdgeInfo()
{
//	for (int i = 0; i < m_eCount; ++i){
	//	cout << "the edge " << i << ":" << endl;
 
		addEdgeToList(1,0);
	        addEdgeToList(2,1);
		addEdgeToList(2,3);
}
 
void GraphList::addEdgeToList(int vFrom, int vTo)
{
	Edge* edge = new Edge();
	edge->vName = vTo;
	edge->next = NULL;
	if (m_vVertex[vFrom].next){
		Edge* tmp = m_vVertex[vFrom].next;
		while(tmp->next){
			tmp = tmp->next;
		}
		tmp->next = edge;
	}else{
		m_vVertex[vFrom].next = edge;
	}
}
 
void GraphList::printGraph()
{
	for (int i = 0; i < m_vCount; ++i){
		Edge* tmp = m_vVertex[i].next;
		cout << m_vVertex[i].vName << "->";
		while(tmp){
			cout << tmp->vName << "->";
			tmp = tmp->next;
		}
		cout << "NULL" << endl;
	}
}
 
// **************************************************************************
// 流程控制
// **************************************************************************
void GraphList::createGraph()
{
        int m_vcount=4;
	inputVertexCount(m_vcount);
	makeVertexArray();
        int m_ecount=3;
	inputEdgeCount(m_ecount);
	inputEdgeInfo();
}

int main()
{
    int i;
    char **classname;
    classname=(char **)malloc(20*sizeof(char *));
	for (i=0;i<20;i++)
		classname[i]=(char *)malloc(256*sizeof(char));
strcpy(classname[0],"grandpa");
strcpy(classname[1],"father");
strcpy(classname[2],"child");
strcpy(classname[3],"mother");


	GraphList graph;
	graph.createGraph();
	graph.printGraph();
	return 0;
}
